<?php

namespace Cframe;

abstract class Controller{
    protected $require = '';
    public function __construct(){
        $this->require = $_REQUEST;
        $this->tpl = new Template();
        $this->init();
    }

    protected function init(){}

    public function assign($name,$value){
        $this->tpl->assign($name,$value);
    }

    public function display($name = '',array $assign = array()){
        if (empty($name)) {
            $function = debug_backtrace()[1]['function'];
            $class = explode("\\", get_called_class());
            array_shift($class);
            $class = implode(DS, $class);
            $function = $class . DS . $function;
            $function = str_replace(APP_NAME . DS,'',$function);
            $base = CON_PATH . str_replace(APP_NAME,BIND_VIEW,$class);
            $this->tpl->display($function,$assign,$base);
        }else{
            $this->tpl->display($name,$assign);
        }
    }

}